<?php
namespace park\controllers;


use common\models\ParkCurrentSpace;
use common\OrderProcess;
use common\Utils;
use Yii;
use yii\web\Controller;
use yii\web\Response;

/**
 * Site controller
 */
class DefaultController extends Controller
{

    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ]
        ];
    }


    /**
     * Displays homepage.
     *
     * @return string
     */
    public function actionIndex($park_space=null)
    {
        if(Yii::$app->request->isPost)
        {
            if(Utils::getParams("pay_type" ) == "1")
            {
                // wehcat pay
                $this->redirect("/pay/wechat/?id=".Utils::getParams("order_id" ));
            }
            else if(Utils::getParams("pay_type" ) == "2")
            {
                // alipay
                $this->redirect("/pay/alipay/?id=".Utils::getParams("order_id" ));
            }
        }
        else
        {
            if($park_space)
            {
                $goPay = Utils::getParams("go-pay",false);
                if( !$goPay)
                    return $this->render('welcome',['park_space'=>$park_space]);
                else
                {
                    $check =  ParkCurrentSpace::findOne(['park_space_id'=>$park_space]);
                    if($check)
                    {

                        $orderinfo = OrderProcess::getOrderInfo($check->park_current_id);
                        return $this->render('fee',['model'=>$orderinfo]);

                    }
                    else
                    {
                        //no parking
                        return $this->render('msg',['msg'=>'暂无停车信息！']);
                    }
                }

            }
            else
            {
                return $this->render('list');
                //return $this->redirect("/?park_space=3768255b-844e-4e0d-94f4-f4da585a295b");
            }
                //return $this->render('msg',['msg'=>'参数错误,请打开支付宝或微信扫码支付']);
        } 
    }


    public function actionPayed()
    {
        return $this->render('msg',['msg'=>'交易完成！']);
    }
}